{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from PIL import Image, ImageDraw\n",
    "from acl_model import Model\n",
    "import cv2\n",
    "import matplotlib.pyplot as plt\n",
    "from acl_util import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "device_id = 0\n",
    "input_size = 112\n",
    "model_path = \"./model/arcface.om\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_dict = {\"path\": \"./data/person.jpg\", \"dtype\": np.uint8}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_org_bgr = cv2.imread(img_dict[\"path\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ACL] init resource stage:\n",
      "[ACL] init resource stage success\n",
      "[Model] class Model init resource stage:\n",
      "[Model] create model output dataset:\n",
      "[Model] create model output dataset success\n",
      "model input size 1\n",
      "input  0\n",
      "model input dims ({'name': 'input_1', 'dimCount': 4, 'dims': [1, 112, 112, 3]}, 0)\n",
      "model input datatype 0\n",
      "==================================================\n",
      "model output size 1\n",
      "output  0\n",
      "model output dims ({'name': 'embedding:0', 'dimCount': 2, 'dims': [1, 512]}, 0)\n",
      "model output datatype 0\n",
      "==================================================\n",
      "[Model] class Model init resource stage success\n"
     ]
    }
   ],
   "source": [
    "model = Model(device_id, model_path, input_size, input_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "93906031080240\n",
      "img_buf_size 150528\n",
      "img_dev_ptr, img_buf_size:  18143016910848 150528\n",
      "[Model] create model input dataset:\n",
      "[Model] create model input dataset success\n",
      "[Model] execute stage:\n",
      "[Model] execute stage success\n"
     ]
    }
   ],
   "source": [
    "# %timeit -n 50 -r 10 \n",
    "embedding = model.run(img_org_bgr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.15966797e-01,  3.49853516e-01, -6.03027344e-02,\n",
       "        -2.87841797e-01,  2.72064209e-02,  1.66503906e-01,\n",
       "        -7.15942383e-02, -2.71759033e-02,  2.53906250e-02,\n",
       "        -2.41546631e-02,  5.61523438e-02,  1.52969360e-02,\n",
       "        -1.20117188e-01,  7.07397461e-02, -1.13586426e-01,\n",
       "        -2.37915039e-01,  1.32446289e-01,  1.97143555e-02,\n",
       "        -1.41845703e-01, -2.23999023e-01, -1.89697266e-01,\n",
       "         1.19628906e-01,  2.51708984e-01, -5.58166504e-02,\n",
       "        -1.45721436e-02, -1.26342773e-01, -1.96075439e-02,\n",
       "         2.65380859e-01, -1.11083984e-01, -1.55029297e-01,\n",
       "        -3.68408203e-01,  1.75537109e-01, -3.13232422e-01,\n",
       "         2.63671875e-01, -8.55102539e-02,  1.06750488e-01,\n",
       "         1.25610352e-01,  6.97631836e-02,  3.54003906e-02,\n",
       "        -1.40380859e-01,  2.57080078e-01, -9.06372070e-02,\n",
       "        -3.89160156e-01, -9.19189453e-02, -2.84423828e-01,\n",
       "         2.24487305e-01,  2.72827148e-02,  2.46826172e-01,\n",
       "         2.15942383e-01, -1.43432617e-01, -5.85021973e-02,\n",
       "        -1.03637695e-01, -1.29241943e-02, -1.72485352e-01,\n",
       "        -2.13623047e-02, -1.82983398e-01,  5.82275391e-02,\n",
       "         2.27661133e-01,  1.15234375e-01,  4.38842773e-02,\n",
       "         1.81030273e-01,  1.08947754e-01,  1.37939453e-01,\n",
       "        -9.74731445e-02,  8.75091553e-03, -3.35449219e-01,\n",
       "         2.25952148e-01, -6.76269531e-01,  3.08349609e-01,\n",
       "         1.14318848e-01, -4.89990234e-01, -2.98583984e-01,\n",
       "         2.33276367e-01,  7.01293945e-02, -2.91259766e-01,\n",
       "         3.72009277e-02,  3.55529785e-03, -1.00036621e-01,\n",
       "         9.51538086e-02,  5.43518066e-02, -1.09802246e-01,\n",
       "        -1.82861328e-01, -1.11328125e-01,  1.22863770e-01,\n",
       "        -2.49877930e-01,  2.11303711e-01, -1.50878906e-01,\n",
       "        -3.10058594e-02, -1.49291992e-01, -2.38952637e-02,\n",
       "         9.21020508e-02,  9.60083008e-02,  3.67431641e-02,\n",
       "         3.51867676e-02,  6.31103516e-02, -5.07354736e-03,\n",
       "        -2.29949951e-02,  2.34008789e-01,  2.76855469e-01,\n",
       "         7.15332031e-02, -4.36706543e-02, -1.44577026e-02,\n",
       "        -3.74450684e-02, -2.09960938e-02, -9.18579102e-02,\n",
       "        -1.48925781e-01, -3.29589844e-01,  2.07519531e-01,\n",
       "         6.28662109e-02, -8.23364258e-02, -6.49414062e-02,\n",
       "         2.59704590e-02,  3.49609375e-01, -2.37121582e-02,\n",
       "         8.93554688e-02, -1.20361328e-01, -2.61840820e-02,\n",
       "         3.50952148e-02,  1.18164062e-01,  1.84082031e-01,\n",
       "        -8.66088867e-02,  1.05590820e-01,  1.97906494e-02,\n",
       "        -1.49917603e-02, -9.32617188e-02,  4.50439453e-02,\n",
       "        -2.81982422e-01,  4.16015625e-01,  2.19726562e-01,\n",
       "        -3.28369141e-02, -8.34350586e-02, -5.93566895e-02,\n",
       "        -1.41357422e-01,  5.07202148e-02,  1.01379395e-01,\n",
       "         4.07104492e-02,  1.08581543e-01, -1.19506836e-01,\n",
       "        -2.05078125e-02, -2.07519531e-03, -1.64794922e-01,\n",
       "         1.46972656e-01, -9.46655273e-02, -3.31054688e-01,\n",
       "         5.85021973e-02, -1.25976562e-01, -2.96630859e-01,\n",
       "        -6.11267090e-02, -1.79595947e-02, -2.16308594e-01,\n",
       "         3.13964844e-01,  1.30615234e-01, -1.19079590e-01,\n",
       "         1.09741211e-01, -3.66455078e-01,  7.98950195e-02,\n",
       "         1.10290527e-01,  2.59552002e-02, -1.88354492e-01,\n",
       "         3.80554199e-02,  5.54504395e-02, -1.84631348e-02,\n",
       "         3.05023193e-02, -2.56835938e-01,  1.13098145e-01,\n",
       "         5.46569824e-02,  3.28857422e-01,  2.57080078e-01,\n",
       "        -1.53827667e-03,  9.85107422e-02, -1.64794922e-01,\n",
       "         6.27441406e-02,  9.95483398e-02,  3.76464844e-01,\n",
       "        -1.56860352e-01,  1.10534668e-01, -2.27050781e-02,\n",
       "         1.13952637e-01, -1.07177734e-01, -1.66931152e-02,\n",
       "        -4.36279297e-01, -9.78088379e-03,  4.49218750e-02,\n",
       "         9.58862305e-02,  1.69677734e-01,  3.68164062e-01,\n",
       "         1.67480469e-01, -4.54101562e-02, -2.89916992e-03,\n",
       "        -3.67126465e-02,  1.85668945e-01,  7.14111328e-02,\n",
       "        -1.43554688e-01,  1.18286133e-01,  1.83227539e-01,\n",
       "         8.49151611e-03, -1.06262207e-01,  4.42810059e-02,\n",
       "        -1.81884766e-02, -8.86230469e-02,  2.05444336e-01,\n",
       "         3.15917969e-01,  2.23999023e-02,  3.82385254e-02,\n",
       "         7.90405273e-02,  4.62951660e-02, -1.31103516e-01,\n",
       "        -5.93566895e-02, -6.74438477e-02, -2.89611816e-02,\n",
       "        -5.38940430e-02,  6.14624023e-02,  4.55932617e-02,\n",
       "        -1.03271484e-01,  1.92565918e-02,  4.25537109e-01,\n",
       "        -2.56805420e-02,  4.09912109e-01,  5.35583496e-02,\n",
       "        -1.09130859e-01, -7.72094727e-02,  1.57104492e-01,\n",
       "         2.98828125e-01, -1.44409180e-01, -2.52838135e-02,\n",
       "         2.77343750e-01, -2.67333984e-01, -1.24511719e-02,\n",
       "         1.12792969e-01,  1.10931396e-02,  2.74658203e-02,\n",
       "        -4.64782715e-02,  4.04541016e-01, -5.24291992e-02,\n",
       "        -5.39855957e-02, -2.32055664e-01, -1.00326538e-02,\n",
       "         2.34527588e-02,  3.95202637e-02,  9.74731445e-02,\n",
       "        -6.02722168e-02, -7.35473633e-02,  2.92205811e-03,\n",
       "         1.56372070e-01, -2.65869141e-01, -3.32832336e-03,\n",
       "         1.75628662e-02, -6.93969727e-02,  1.64550781e-01,\n",
       "         5.78613281e-02,  1.82495117e-01, -4.76684570e-02,\n",
       "        -1.40136719e-01, -3.52382660e-04, -4.86572266e-01,\n",
       "         1.05957031e-01, -4.06188965e-02,  1.72607422e-01,\n",
       "        -2.18261719e-01, -1.77001953e-01, -2.06176758e-01,\n",
       "         8.83789062e-02,  5.71289062e-02, -2.41577148e-01,\n",
       "        -1.53564453e-01,  7.69042969e-02,  4.14550781e-01,\n",
       "        -8.84399414e-02,  4.80651855e-03,  2.69531250e-01,\n",
       "         1.31347656e-01, -2.89306641e-01,  2.24975586e-01,\n",
       "        -2.09350586e-01,  1.73492432e-02,  1.12792969e-01,\n",
       "         7.02514648e-02, -2.82745361e-02, -4.34875488e-02,\n",
       "        -4.58984375e-02,  4.18457031e-01,  6.61621094e-02,\n",
       "        -2.18383789e-01, -6.69555664e-02, -2.81005859e-01,\n",
       "        -5.61904907e-03, -3.93981934e-02,  2.37182617e-01,\n",
       "        -2.70751953e-01,  2.88818359e-01, -2.59033203e-01,\n",
       "         1.62231445e-01, -6.32934570e-02, -1.82983398e-01,\n",
       "        -2.29370117e-01,  1.37042999e-03,  3.70788574e-02,\n",
       "         4.36035156e-01,  1.28662109e-01,  3.24707031e-02,\n",
       "        -4.99572754e-02,  2.34863281e-01, -3.43017578e-01,\n",
       "        -2.60986328e-01, -2.65655518e-02,  1.87500000e-01,\n",
       "         1.42456055e-01, -3.32946777e-02, -1.74682617e-01,\n",
       "        -1.00463867e-01, -1.76696777e-02,  1.62841797e-01,\n",
       "         1.86645508e-01, -1.23413086e-01,  2.81250000e-01,\n",
       "        -9.73510742e-02,  1.31988525e-02, -2.38281250e-01,\n",
       "         1.28173828e-01, -1.45385742e-01,  3.10974121e-02,\n",
       "         4.30908203e-01, -1.09008789e-01, -1.64550781e-01,\n",
       "         1.47460938e-01, -1.89575195e-01,  1.31958008e-01,\n",
       "        -3.95507812e-01, -2.50732422e-01, -5.47180176e-02,\n",
       "        -5.29174805e-02, -2.68310547e-01, -2.13256836e-01,\n",
       "        -1.82495117e-01, -1.29150391e-01,  2.67639160e-02,\n",
       "        -7.65991211e-02, -6.65283203e-02, -4.07470703e-01,\n",
       "         1.20666504e-01,  7.50732422e-02,  1.69189453e-01,\n",
       "         2.43988037e-02, -1.31958008e-01, -1.86523438e-01,\n",
       "        -1.52343750e-01, -7.13500977e-02, -2.05383301e-02,\n",
       "         6.49414062e-02, -4.64477539e-02, -5.27648926e-02,\n",
       "         2.52197266e-01, -2.00195312e-01, -7.11059570e-02,\n",
       "        -3.00598145e-02,  2.85186768e-02,  2.33642578e-01,\n",
       "         2.92724609e-01, -9.29565430e-02, -1.11083984e-01,\n",
       "         1.47583008e-01, -2.46238708e-03,  1.83471680e-01,\n",
       "         2.51708984e-01,  2.25708008e-01, -4.21752930e-02,\n",
       "        -2.02514648e-01, -3.92822266e-01,  4.45556641e-02,\n",
       "        -9.12475586e-02, -1.50756836e-01, -2.92015076e-03,\n",
       "         7.82470703e-02, -7.22656250e-02,  2.05810547e-01,\n",
       "        -1.23962402e-01,  7.38525391e-02, -1.12609863e-01,\n",
       "         4.54101562e-02, -2.22900391e-01, -2.29034424e-02,\n",
       "         5.85556030e-03,  1.64947510e-02,  1.20788574e-01,\n",
       "         1.92993164e-01, -3.58276367e-02,  2.92236328e-01,\n",
       "        -5.37414551e-02, -9.47875977e-02, -3.11126709e-02,\n",
       "        -1.82250977e-01, -2.77343750e-01, -2.31323242e-01,\n",
       "         1.64062500e-01,  1.73187256e-02,  1.34399414e-01,\n",
       "         1.59301758e-02, -2.93121338e-02, -5.04150391e-02,\n",
       "        -6.80541992e-02,  1.26220703e-01,  1.14257812e-01,\n",
       "         2.50396729e-02, -1.16271973e-01, -2.78167725e-02,\n",
       "        -1.18103027e-01,  2.67486572e-02, -1.06140137e-01,\n",
       "         5.63354492e-02,  1.04248047e-01,  9.24072266e-02,\n",
       "        -1.73339844e-01,  2.32543945e-01, -2.68798828e-01,\n",
       "         1.81884766e-01, -1.46972656e-01,  6.33544922e-02,\n",
       "         1.17736816e-01,  5.85327148e-02,  1.78222656e-01,\n",
       "        -1.89575195e-01,  5.45654297e-02, -5.90515137e-03,\n",
       "        -6.51855469e-02,  1.74560547e-01,  1.48681641e-01,\n",
       "        -3.80554199e-02, -2.08740234e-01, -7.91625977e-02,\n",
       "         2.08007812e-01,  3.64685059e-02,  5.33447266e-02,\n",
       "        -2.02789307e-02,  9.75952148e-02,  2.61993408e-02,\n",
       "        -1.25854492e-01, -1.07482910e-01, -6.93511963e-03,\n",
       "        -1.77612305e-01, -2.97851562e-01, -1.07543945e-01,\n",
       "         3.76708984e-01,  1.01989746e-01, -2.34008789e-01,\n",
       "        -6.13403320e-02,  6.48193359e-02,  2.25677490e-02,\n",
       "        -1.72973633e-01, -2.51464844e-01, -3.15246582e-02,\n",
       "         2.38525391e-01, -7.45239258e-02, -2.63671875e-01,\n",
       "         3.18908691e-02,  1.67236328e-01,  1.33438110e-02,\n",
       "        -1.43798828e-01,  7.44018555e-02, -6.92138672e-02,\n",
       "         1.33666992e-01, -2.59552002e-02, -2.06542969e-01,\n",
       "        -1.29150391e-01, -4.09240723e-02,  1.13891602e-01,\n",
       "         1.97509766e-01,  3.53027344e-01, -4.85839844e-01,\n",
       "        -7.08007812e-03,  7.43408203e-02,  1.43554688e-01,\n",
       "        -6.26754761e-03,  7.56835938e-02, -1.77246094e-01,\n",
       "         1.95145607e-04, -6.19506836e-02, -1.33178711e-01,\n",
       "        -1.11755371e-01, -8.57543945e-02,  3.93554688e-01,\n",
       "        -1.65252686e-02, -1.31469727e-01, -1.35131836e-01,\n",
       "        -6.14929199e-02,  4.69970703e-02, -1.21307373e-02,\n",
       "         7.47070312e-02,  1.03576660e-01,  9.45434570e-02,\n",
       "         5.18798828e-02,  2.45239258e-01, -4.27246094e-03,\n",
       "        -1.38671875e-01,  1.83837891e-01, -2.58331299e-02,\n",
       "         5.93261719e-02,  4.53857422e-01,  2.38647461e-01,\n",
       "        -2.33398438e-01, -7.52563477e-02,  1.27075195e-01,\n",
       "        -3.98193359e-01, -3.47656250e-01,  1.00708008e-01,\n",
       "         1.55761719e-01, -2.94677734e-01,  1.07116699e-01,\n",
       "        -1.59301758e-01, -1.64947510e-02, -4.17785645e-02,\n",
       "        -1.30493164e-01, -4.80712891e-01]], dtype=float32)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "embedding"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
